package com.fanwj.citrus

import com.fanwj.citrus.aidl.IFrontend
import com.fanwj.citrus.aidl.IFrontend.KeyboardConfig
import com.fanwj.citrus.aidl.IFrontend.KeyboardData
import com.fanwj.citrus.applets.keyboard.SoftwareKeyboard
import com.fanwj.citrus.disk_shader_cache.DiskShaderCacheProgress
import com.fanwj.citrus.features.input.NativeInput

class Frontend : IFrontend.Stub() {
    override fun NativeLibrary_startMainLooper(): Int {
        return NativeLibrary.startMainLooper()
    }

    override fun NativeLibrary_updateProgress(max: Long, progress: Long): Boolean {
        return NativeLibrary.updateProgress(max, progress)
    }

    override fun NativeLibrary_exitEmulationActivity(resultCode: Int) {
        NativeLibrary.exitEmulationActivity(resultCode);
    }

    override fun NativeLibrary_onEmulationStarted() {
        NativeLibrary.onEmulationStarted()
    }

    override fun NativeLibrary_onEmulationStopped(status: Int) {
        NativeLibrary.onEmulationStopped(status)
    }

    override fun NativeLibrary_onProgramChanged(programIndex: Int) {
        NativeLibrary.onProgramChanged(programIndex)
    }

    override fun NativeLibrary_getParentDirectory(path: String): String {
        return NativeLibrary.getParentDirectory(path)
    }

    override fun NativeLibrary_getFilename(path: String): String {
        return NativeLibrary.getFilename(path)
    }

    override fun NativeLibrary_getSize(path: String): Long {
        return NativeLibrary.getSize(path)
    }

    override fun NativeLibrary_isDirectory(path: String): Boolean {
        return NativeLibrary.isDirectory(path)
    }

    override fun NativeLibrary_exists(path: String): Boolean {
        return NativeLibrary.exists(path)
    }

    override fun NativeLibrary_openContentUri(path: String, mode: String, fdAddr: Long) {
        return NativeLibrary.openContentUri(path, mode, fdAddr)
    }

    override fun NativeLibrary_setCurrentThreadName(name: String): Long {
        val thread = Thread.currentThread()
        if (name.isNotEmpty()) thread.name = name
        return thread.id
    }

    override fun NativeInput_getAxesOfController(guid: String): IntArray {
        return NativeInput.getAxesOfController(guid)
    }

    override fun NativeInput_getKeysOfController(guid: String): IntArray {
        return NativeInput.getKeysOfController(guid)
    }

    override fun NativeInput_getPropertyOfControllers(): Array<String> {
        return NativeInput.getPropertyOfControllers()
    }

    override fun SoftwareKeyboard_executeNormal(config: KeyboardConfig): KeyboardData {
        return SoftwareKeyboard.executeNormal(config)
    }

    override fun SoftwareKeyboard_executeInline(config: KeyboardConfig) {
        SoftwareKeyboard.executeInline(config)
    }

    override fun DiskShaderCacheProgress_loadProgress(stage: Int, progress: Int, max: Int) {
        DiskShaderCacheProgress.loadProgress(stage, progress, max)
    }
}